<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">无机结合料稳定材料最大干密度、最佳含水量试验检测报告</div>
        <div class="codeText">
          <tr>BGLQ09003F</tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>报告编号：</span>
          <span class="placeholder">{{ form.baogbh }}</span>
        </div>
      </div>
      <div class="table-border">
        <!-- .........................1111111111111111111111111111111......................................................... -->
        <table height="210px" class="top-table">
          <tbody>
            <tr>
              <td height="40" align="center" width="15%">
                <span style="width:90px;display:inline-block">施工/委托单位</span>
              </td>
              <td width="35%" bgcolor="#ffffff">
                <span>{{ form.shigwtdw }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width:90px;display:inline-block">工程名称</span>
              </td>
              <td bgcolor="#ffffff" width="35%">
                <span>{{ form.gongcmc }}</span>
              </td>
            </tr>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width:90px;display:inline-block">工程部位/用途</span>
              </td>
              <td colspan="3">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ 'placeholder': !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>

                <span>；样品数量：</span>
                <span :class="{ 'placeholder': !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ 'placeholder': !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ 'placeholder': !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                  @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView"
                  @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark"
                  @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="180px" class="middle-table">
          <tr trindex="0">
            <td colspan="1" width="15%">材料名称规格</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg1 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg2 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg3 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg4 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg5 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg6 }}</td>
            <td colspan="1" class="middele-td">{{ form.cailmcgg7 }}</td>
          </tr>
          <tr trindex="1">
            <td colspan="1" width="15%">产地</td>
            <td colspan="1" class="middele-td">{{ form.chand1 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand2 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand3 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand4 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand5 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand6 }}</td>
            <td colspan="1" class="middele-td">{{ form.chand7 }}</td>
          </tr>
          <tr trindex="2">
            <td colspan="1" height="40" width="15%">比例</td>
            <td colspan="1" class="middele-td">{{ form.bil1 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil2 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil3 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil4 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil5 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil6 }}</td>
            <td colspan="1" class="middele-td">{{ form.bil7 }}</td>
          </tr>
        </table>
        <table height="350px" class="middle-table">
          <tr trindex="5">
            <td colspan="2" height="40" class="td2-1">试验次数</td>
            <td colspan="2" class="td2-2">1</td>
            <td colspan="2" class="td2-2">2</td>
            <td colspan="2" class="td2-2">3</td>
          </tr>
          <tr trindex="16">
            <td colspan="2" class="td2-1">含水量(%)</td>
            <td colspan="1">{{ form.baDetailVos[0].hansl1 }}</td>
            <td colspan="1">{{ form.baDetailVos[0].hansl2 }}</td>
            <td colspan="1">{{ form.baDetailVos[1].hansl1 }}</td>
            <td colspan="1">{{ form.baDetailVos[1].hansl2 }}</td>
            <td colspan="1">{{ form.baDetailVos[2].hansl1 }}</td>
            <td colspan="1">{{ form.baDetailVos[2].hansl2 }}</td>
          </tr>
          <tr trindex="17">
            <td colspan="2">平均含水量(%)</td>
            <td colspan="2">{{ form.baDetailVos[0].hanslpjz }}</td>
            <td colspan="2">{{ form.baDetailVos[1].hanslpjz }}</td>
            <td colspan="2">{{ form.baDetailVos[2].hanslpjz }}</td>
          </tr>
          <tr trindex="18">
            <td colspan="2">干密度(g/cm3)</td>
            <td colspan="2">{{ form.baDetailVos[0].ganmd }}</td>
            <td colspan="2">{{ form.baDetailVos[1].ganmd }}</td>
            <td colspan="2">{{ form.baDetailVos[2].ganmd }}</td>
          </tr>
          <tr trindex="19">
            <td colspan="2">干密度平均值(g/cm3)</td>
            <td colspan="6">{{ form.ganmdpjz }}</td>
          </tr>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="120px" class="bottom-table">
          <tr>
            <td colspan="14" height="60px" style="border-bottom-width: 1px;">
              <span v-if="isPdf" class="textarea-span">{{ form.jiancjl }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.jiancjl" @focus="handleFocus('jiancjl')"
                @dblclick.native="getJcjl()" />
            </td>
          </tr>
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">审核：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">批准：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { handleFocus, emptyConvert, uniqueStr } from "@/views/reportForms/utils";
import { getWjjhlWdclzdgmdbgBsInfo, queryJcjl } from "@/api/report_wjjhl/wjjhlWdclzdgmdbgBsInfo";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";
export default {
  name: "tgsybg",
  components: {
    BsJudgeBaseView,
    BsInstrumentView,
    BsJiancyjView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data () {
    return {
      // 表单参数
      form: {
        baDetailVos: [{}, {}, {}, {}]
      }
    };
  },
  watch: {
    isPdf (newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created () {
    this.getInfo();
  },
  mounted () {
    // 检测依据
    Bus.$on("setWdclzdgmdBgJiancyj", (data) => {
      const { jiancyj, jiancyjIds } = data;
      const str = jiancyj + (this.form.jiancyj ? "、" + this.form.jiancyj : "");
      const ids = jiancyjIds + (this.form.jiancyjIds ? "," + this.form.jiancyjIds : "");
      this.form.jiancyj = uniqueStr(str, "、");
      this.form.jiancyjIds = uniqueStr(ids, ",");
    });
    // 主要设备
    Bus.$on("setWdclzdgmdBgZhuyyqsbmcjbh", (data) => {
      const { zhuyyqsbmcjbh, shebIds } = data;
      const str = zhuyyqsbmcjbh + (this.form.zhuyyqsbmcjbh ? "、" + this.form.zhuyyqsbmcjbh : "");
      const ids = shebIds + (this.form.shebIds ? "," + this.form.shebIds : "");
      this.form.zhuyyqsbmcjbh = uniqueStr(str, "、");
      this.form.shebIds = uniqueStr(ids, ",");
    });
    // 各报表给报告传值
    Bus.$on("setWdclzdgmdBgJiancjg", (data) => {
      let arr = ["ganmdpjz"];
      for (let index = 1; index <= 7; index++) {
        arr.push("cailmcgg" + index);
        arr.push("chand" + index);
        arr.push("bil" + index);
      }
      arr.forEach((item) => {
        this.form[item] = data[item];
      });

      // 赋值baDetailVos
      let array = ["hansl1", "hansl2", "hanslpjz", "ganmd"];
      data.baDetailVos.forEach((item, index) => {
        array.forEach((subItem) => {
          this.form.baDetailVos[index][subItem] = item[subItem];
        });
      });
    });
  },
  beforeDestroy () {
    // 或者你可以使用其他合适的生命周期钩子
    // 停止监听事件
    Bus.$off("setWdclzdgmdBgJiancyj");
    Bus.$off("setWdclzdgmdBgZhuyyqsbmcjbh");
    Bus.$off("setWdclzdgmdBgJiancjg");
  },
  methods: {
    // 获取详情
    getInfo () {
      getWjjhlWdclzdgmdbgBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.jiancjl) {
          this.form.jiancjl = "检测结论：";
        }
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    // 显示检测依据列表
    showBsJiancyjView () {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj (info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },
    // 显示判定依据列表
    showBsJudgeBaseView () {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge (info) {
      if (!info || !info.label) {
        return;
      }
      if (!this.form.pandyj) {
        this.form.pandyj = info.label;
      } else {
        if (info && info.label) {
          this.form.pandyj += "、" + info.label;
        }
      }
      // 添加指标 info.list
    },
    // 显示仪器列表
    showBsInstrumentView () {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument (info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },
    // 获取检测结论
    getJcjl () {
      const form = JSON.parse(JSON.stringify(this.form));
      queryJcjl(emptyConvert(form)).then((res) => {
        const info = res.data;
        this.form.jiancjl = info.jiancjl;
      });
    },
    submitForm () {
      return this.form;
    },
    handleFocus (event) {
      handleFocus(event, this.page, this.form[event]);
    }
  }
};
</script>

<style scoped>
.middele-td {
  width: calc((100% - 15%) / 7);
}

.td2-1 {
  width: calc((100% - 15%) / 7 + 15%);
}

.td2-2 {
  width: calc((100% - 15%) / 7 * 2);
}
</style>
